// ActionScript file

	import mx.managers.PopUpManager;
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.ResultEvent;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.events.CloseEvent;
	

	private function onListar( event:ResultEvent ):void{
		dg.dataProvider = event.result as Object;
		bteditar.enabled = true;
		dg.enabled = true;
		btexcluir.enabled = true;
		btnovo.enabled = true;
		content.enabled = false;
		btcancelar.enabled = false;
		btsalvar.enabled = false;
		dg.selectedIndex = 0;
	}
	
	private function salvar():void{
		var a:ArrayCollection = new ArrayCollection();
		a.addItem( { 
	
			"Id" : pn_Id.text, 
			"Descricao" : pn_Descricao.text
		} );
		Remote.salvar(a);
	}
	
	public function excluir():void{
		Alert.yesLabel='Sim';
		Alert.noLabel='Não';
		Alert.show('Deseja realmente excluir esse registro?','ATENÇÃO',Alert.YES|Alert.NO, null, excluirResult);
	}public function excluirResult(e:CloseEvent):void{
		if(e.detail == Alert.YES){
			Remote.excluir( pn_Id.text );
		}
	}
	
	
	private function editar():void{
		dg.enabled = false;
		bteditar.enabled = false;
		btexcluir.enabled = false;
		btnovo.enabled = false;
		content.enabled = true;
		btcancelar.enabled = true;
		btsalvar.enabled = true;
	}
	
	private function cancelar():void{
		bteditar.enabled = true;
		dg.enabled = true;
		btexcluir.enabled = true;
		btnovo.enabled = true;
		content.enabled = false;
		btcancelar.enabled = false;
		btsalvar.enabled = false;
	}	
	
	private function novo():void{
		content.enabled = true;
		dg.enabled	=	false;
		btsalvar.enabled = true;
		btcancelar.enabled = true;
		resets();
	}
	
	
	private function resets():void{	
		pn_Id.text	= 	null;
		pn_Descricao.text	= 	null;
 	}	